package com.ruoyi.cscec.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.cscec.domain.Online;
import com.ruoyi.cscec.service.IOnlineService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 实时监控Controller
 *
 * @author ruoyi
 * @date 2021-09-29
 */
@RestController
@RequestMapping("/online")
public class OnlineController extends BaseController
{
    @Autowired
    private IOnlineService onlineService;

    /**
     * 查询实时监控列表
     */
    @PreAuthorize(hasPermi = "online:cscec:list")
    @GetMapping("/list")
    public TableDataInfo list(Online online)
    {
        startPage();
        List<Online> list = onlineService.selectOnlineList(online);
        return getDataTable(list);
    }

    /**
     * 导出实时监控列表
     */
    @PreAuthorize(hasPermi = "online:cscec:export")
    @Log(title = "实时监控", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Online online) throws IOException
    {
        List<Online> list = onlineService.selectOnlineList(online);
        ExcelUtil<Online> util = new ExcelUtil<Online>(Online.class);
        util.exportExcel(response, list, "实时监控数据");
    }

    /**
     * 获取实时监控详细信息
     */
    @PreAuthorize(hasPermi = "online:cscec:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(onlineService.selectOnlineById(id));
    }

    /**
     * 新增实时监控
     */
    @PreAuthorize(hasPermi = "online:cscec:add")
    @Log(title = "实时监控", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Online online)
    {
        return toAjax(onlineService.insertOnline(online));
    }

    /**
     * 修改实时监控
     */
    @PreAuthorize(hasPermi = "online:cscec:edit")
    @Log(title = "实时监控", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Online online)
    {
        return toAjax(onlineService.updateOnline(online));
    }

    /**
     * 删除实时监控
     */
    @PreAuthorize(hasPermi = "online:cscec:remove")
    @Log(title = "实时监控", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(onlineService.deleteOnlineByIds(ids));
    }
}
